# Contributor: TBK <alpine@jjtc.eu>
# Maintainer: TBK <alpine@jjtc.eu>
pkgname=box2d
pkgver=2.4.1
pkgrel=2
pkgdesc="2D Physics Engine for Games"
url="https://box2d.org/"
arch="all"
license="MIT"
makedepends="
	cmake
	doxygen
	libx11-dev
	libxcursor-dev
	libxinerama-dev
	libxrandr-dev
	ninja
	"
subpackages="$pkgname-doc $pkgname-dev"
source="$pkgname-$pkgver.tar.gz::https://github.com/erincatto/box2d/archive/v$pkgver.tar.gz"

build() {
	if [ "$CBUILD" != "$CHOST" ]; then
		CMAKE_CROSSOPTS="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi
	cmake -B build \
		-GNinja \
		-DCMAKE_BUILD_TYPE=MinSizeRel \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DBUILD_SHARED_LIBS=ON \
		-DBOX2D_BUILD_DOCS=ON \
		-DBOX2D_BUILD_TESTBED=OFF \
		-DBOX2D_BUILD_UNIT_TESTS=ON \
		$CMAKE_CROSSOPTS
	cmake --build build
}

check() {
	echo "Running unit_test"
	build/bin/unit_test
}

package() {
	DESTDIR="$pkgdir" cmake --install build
}

sha512sums="
d900f925b77906777719c91488bdc5e2df1ad1f4a8ca39a574229f5e57070e3a843bdd7530e817112605fde6d82145c872d8afdfc65b84531a73199098c81162  box2d-2.4.1.tar.gz
"
